<?php
	include_once 'isLogin.php';
	
	$table_name = "focus";
	
	if($_POST['submit']){
		if($_GET['id']!=false){
			$oldImg=$commonc->getInfo($table_name,$_GET['id'],'img');
			$img=$oldImg['img'];
		}
		if($_FILES['img']['name']!=''){
			$annexFolder = "../upload/focus/index/";
			$smallFolder = $annexFolder;
			$upimg = new uploadImg();
			$img = $upimg->upLoad('img',$annexFolder);
			$img_small = $upimg->smallImg($annexFolder.$img,$smallFolder);
			if($_GET['id']!=false){
				@unlink('../upload/focus/index/'.$oldImg['img']);
			}
		}else{
			echo $commonc->submitAlert('请选择要上传的图片','img_add.php');
			exit();
		}
		
		$arr = array('title'=>$_POST['title'],'link'=>$_POST['link'],'img'=>$img
					,'date'=>date("Y-m-d"),'class'=>$_GET['class']);
		if($_GET['id']!=false){
			$commonc->update($table_name,$arr,'id='.$_GET['id']);
			echo $commonc->submitAlert('成功','img_add.php?id='.$_GET['id']);
		}else{
			$commonc->insert($table_name,$arr);
			echo $commonc->submitAlert('成功','img_add.php');
		}
	}
	
	if($_GET['id']!=false){
		$row=$commonc->getInfo($table_name,$_GET['id']);
	}
	
	$smarty->assign('image',$row);
	$smarty->display("focus_add.html");
?>